package com.niit.TopN.SchoolTop10;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import com.niit.bean.SchoolTop100Bean;

import java.io.IOException;

public class SchoolTop100Mapper extends Mapper<LongWritable, Text, SchoolTop100Bean,Text> {
    SchoolTop100Bean outKey = new SchoolTop100Bean();
    Text outValue = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] fields = value.toString().split("\t");
        String school = fields[0];
        String[] StudentsNum =fields[2].split("：");
        String[] ActiveDays =fields[1].split("：");
        long studentsNum = Long.parseLong(StudentsNum[1]) ;
        long activeDays = Long.parseLong(ActiveDays[1]);
        outKey.set(studentsNum,activeDays);
        outValue.set(school);
        context.write(outKey,outValue);
    }
}
